<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/28
 * Time: 12:20
 */
namespace app\swoole\controller;

use think\swoole\Server;

class Swoole extends Server
{
    protected $host = '0.0.0.0';
    protected $port = 8877;
    protected $serverType = 'socket';
    protected $option = [
        'worker_num'	=> 4,
        //'daemonize'	=> true,
        'backlog'	=> 128
    ];

    public function index()
    {
        return '';
    }

    public function onMessage($server, $frame)
    {
        $server->push($frame->fd, '我收到信息');
    }

    public function onReceive($server, $fd, $from_id, $data)
    {
        $server->send($fd, 'Swoole: '.$data);
    }
}